package com.student.controller;

import com.student.VO.PhAdminVO;
import com.student.VO.PhAdminVOs;
import com.student.VO.UserVO;
import com.student.dto.ResponseDto;
import com.student.service.SnackAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: makeups
 * @BelongsPackage: com.student.controller
 * @Author: 小徐
 * @CreateTime: 2024-12-18 22:55
 * @Description: TODO
 * @Version: 管理员
 */
@RestController
@RequestMapping("admin")
public class SnackAdminController {

    @Autowired
    private SnackAdminService snackAdminService;

    @RequestMapping("restPassword")
    public ResponseDto restPassword(@RequestParam("id") Integer id,
                                    @RequestParam("oldPassword") String oldPassword,
                                    @RequestParam("newPassword") String newPassword) {
   return snackAdminService.restPassword(id,oldPassword,newPassword);
    }


    /**
     * 做登录操作
     * @param phUserVO
     * @return
     */
    @PostMapping("doLogin")
    public ResponseDto adminLogin(@RequestBody UserVO phUserVO) {
        System.err.println(phUserVO);
        return snackAdminService.adminLogin(phUserVO);
    }

    //查询全部数据  使用mybatis分页插件 渲染用户的信息做分页
    @PostMapping(value = "insertPagination")
    @CrossOrigin
    public ResponseDto insertPagination(@RequestBody PhAdminVO phAdminVO) {


        return snackAdminService.insertPagination(phAdminVO);

    }

    //    修改状态
    @GetMapping("updateStatics")
    @CrossOrigin
    public ResponseDto updateStatics(@RequestParam("status") Integer status, @RequestParam("id") Integer id) {

        System.err.println("状态值" + status);
        return snackAdminService.updateStatics(status, id);

    }


    /**
     * 重置密码
     *
     * @param id
     * @return
     */
    @GetMapping("resUserPassword")
    @CrossOrigin
    public ResponseDto resUserPassword(@RequestParam("id") Integer id) {

        return snackAdminService.resUserPassword(id);
    }


    /**
     * 删除用户
     *
     * @param id
     * @return
     */
    @GetMapping("deleteUser")
    @CrossOrigin
    public ResponseDto deleteUser(@RequestParam("id") Integer id) {

        return snackAdminService.deleteUser(id);
    }


    //查询全部数据  使用mybatis分页插件

    /**
     * 这边是查询管理员信息
     *
     * @param phAdminVO
     * @return
     */
    @PostMapping(value = "adminInsertPage")
    @CrossOrigin
    public ResponseDto adminInsertPage(@RequestBody PhAdminVO phAdminVO) {
        System.err.println(phAdminVO);

        return snackAdminService.adminInsertPage(phAdminVO);

    }

    /**
     * 获取所有的角色名称
     *
     * @return
     */
    @GetMapping("getRole")
    public ResponseDto getRoleName() {
        return snackAdminService.getRoleName();
    }

    //    修改角色

    /**
     * 修改角色
     *
     * @param roleId
     * @param id
     * @return
     */
    @GetMapping("updateAdminRoleId")
    @CrossOrigin
    public ResponseDto updateAdminRoleId(@RequestParam("roleId") Integer roleId, @RequestParam("id") Integer id) {


        return snackAdminService.updateAdminRoleId(roleId, id);

    }

    /**
     * 删除管理员
     *
     * @param id
     * @return
     */
    @GetMapping("deleteAdmin")
    @CrossOrigin
    public ResponseDto deleteAdmin(@RequestParam("id") Integer id) {

        return snackAdminService.deleteAdmin(id);
    }

    /**
     * 添加管理员  并且设置角色id
     *
     * @param phAdminVOs
     * @return
     */
    @PostMapping("addAdminAccountAndPassword")
    public ResponseDto addAdminAccountAndPassword(@RequestBody PhAdminVOs phAdminVOs) {

        return snackAdminService.addAdminAccountAndPassword(phAdminVOs);


    }

}